<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>definepropety</title>
    <script>
        function observer (data){
            return new Proxy(data,{
                get(target,attr){
                    return target[attr];
                },
                set(target, attr, newValue){
                    target[attr] = newValue;
                    title.innerHTML = newValue;
                }
            })
        }
        
    </script>
</head>
<body>
    <div id="app">
        <button id="btn">设置</button>
        <p id="title">这是一个测试</p>

    </div>
    <script>
        let title = document.querySelector('#title');
        let btn = document.querySelector('#btn');
        let data = {
            title:'Hello , 测试',
        }
        data = observer(data);
        // 劫持 


        btn.onclick = function(){
            data.title = '改变了';
            console.log(data);
        }
    </script>
</body>
</html>